import serial
import time
from utils import *

ser = serial.Serial('COM5', 9600, parity=serial.PARITY_EVEN, bytesize=serial.EIGHTBITS, stopbits=serial.STOPBITS_ONE)

if ser.is_open:
    print('串口已经打开')

# data_to_send = [0x03, 0x03, 0x02, 0x76, 0x00, 0x01, 0x65, 0x8A]
# data_to_send2 = [0x03, 0x03, 0x02, 0xE0, 0x00, 0x01, 0x85, 0xA6]
# data_to_send = [0x01, 0x03, 0x00, 0x01, 0x00, 0x03, 0x55, 0xE9]
data_to_send2 = [0x68, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x68, 0x04, 0x04, 0x33, 0xF3, 0xF3, 0x3B, 0x2E, 0x16]
data_to_send = [0x68, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x68, 0x04, 0x08, 0x37, 0x33, 0x34, 0x34, 0x00, 0x02, 0xAA, 0xE9, 0x46, 0x16]

data_to_send_clr = [0x68, 0x95, 0x63, 0x10, 0x04, 0x22, 0x20, 0x68, 0x04, 0x04, 0x33, 0xF3, 0xF3, 0x3B, 0x7A, 0x16]
data_to_send_read = [0x68, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x68, 0x04,0x06, 0x34, 0xF3,0xF3,0x3B,0x34,0x34,0x9A,0x16]

addr1 = [0x95, 0x63, 0x10, 0x04, 0x22, 0x20]
addr2 = [0x92, 0x62, 0x10, 0x04, 0x22, 0x20]
addr5 = [0x56, 0x63, 0x10, 0x04, 0x22, 0x20]


print(send(ser, "read_i", addr5))
# ser.write(bytes(data_to_send_clr))
# print(ser.read_until(b'\x16').hex())
# ser.write(bytes(data_to_send))
# t = time.time()
# print(t)
# #time.sleep(180)
# print(ser.read_until(b'\x16').hex())#好像启动一会自己就好了,如果刚运行玩马上再运行一次第一个拓扑信号是会发送失败的
# time.sleep(30)
# ser.write(bytes(data_to_send_read))
# print(ser.read_until(b'\x16').hex())
# #两个触发信号之间要间隔30s，并且触发后过15s才可以读取，连续发送信号存在困难,难道是要先切换成写的状态再休眠吗(不对，看似正确的数其实是clear的返回值)
# print(11)
# time.sleep(180)
# ser.write(bytes(data_to_send))
# print(ser.read_until(b'\x16').hex())
# print(11)
# exit()
# time.sleep(180)
# ser.write(bytes(data_to_send))
# print(ser.read_until(b'\x16').hex())
# print(11)
# exit()
